using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Marin.Entities;

namespace Marin.Repository.Mapping
{
    public class DetalleEgresoMap : EntityTypeConfiguration<DetalleEgreso>
    {
        public DetalleEgresoMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Item, t.IdEgreso });

            // Properties
            this.Property(t => t.Item)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

   
            this.Property(t => t.Motivo)
                .HasMaxLength(200);

          
            this.Property(d => d.Cantidad)
                      .HasPrecision(9, 2)
                      .IsRequired();

            this.Property(d => d.PrecioUnt)
                .HasPrecision(9, 2)
                .IsRequired();

            this.Ignore(d => d.Monto);

            // Table & Column Mappings
            this.ToTable("DetalleEgreso");
            this.Property(t => t.Item).HasColumnName("Item");
            this.Property(t => t.Motivo).HasColumnName("Motivo");
            this.Property(d => d.Cantidad).HasColumnName("Cantidad");
            this.Property(d => d.PrecioUnt).HasColumnName("PrecioUnt");

            // Relationships
            this.HasRequired(t => t.Cuenta)
                .WithMany()
                .HasForeignKey(d => d.IdCuenta)
                .WillCascadeOnDelete(false);



            this.HasRequired(t => t.Egreso)
                .WithMany(t => t.DetalleEgresoes)
                .HasForeignKey(d => d.IdEgreso)
                .WillCascadeOnDelete(false);

        }
    }
}
